﻿	function calendar(thisDate, arrdiv) {
		var toDate		= new Date();
		var toYear		= toDate.getFullYear();
		var toMonth		= toDate.getMonth() + 1;
		var toDays		= toDate.getDate();
		var toWeek		= toDate.getDay();
		var totalDate	= toYear + '' + dateFormat(toMonth) + '' + dateFormat(toDays);

		if (thisDate != null || thisDate != undefined) {
			toYear	= thisDate[0];
			toMonth	= thisDate[1];
		}

		
		var prevY = toYear;
		var prevM = toMonth - 1;
		var nextY = toYear;
		var nextM = toMonth + 1;

		if (toMonth == 1) {
			prevY -= 1;
			prevM  = 12;
		} else if (toMonth == 12) {
			nextY += 1;
			nextM  = 1;
		}

		var tmp = '';
		tmp += '<table cellspacing="0" cellpadding="0" border="0" class="cheader">';
		tmp += '<tr>';
		if (changebtn == 1) {
			tmp += '<td><a href="javascript:void(0);" onclick="calendar([' + prevY + ',' + prevM + ']);">&lt;&lt;</a></td>';
		}
		tmp += '<th>' + toYear + '年' + toMonth + '月' + '</th>';
		if (changebtn == 1) {
			tmp += '<td><a href="javascript:void(0);" onclick="calendar([' + nextY + ',' + nextM + ']);">&gt;&gt;</a></td>';
		}
		tmp += '</tr>';
		tmp += '<table cellspacing="0" cellpadding="0" border="0" class="cbody">';
		tmp += '<tr>';
		tmp += '<th>日</th>';
		tmp += '<th>月</th>';
		tmp += '<th>火</th>';
		tmp += '<th>水</th>';
		tmp += '<th>木</th>';
		tmp += '<th>金</th>';
		tmp += '<th>土</th>';
		tmp += '</tr>';

		var count = 0;

		for (var i = 1;i <= 31;i++) {
			
			var classAry = [];
			var classStr = '';

			var cDate	= new Date(toYear, toMonth - 1, i);
			var cYear	= cDate.getFullYear();
			var cMonth	= cDate.getMonth() + 1;
			var cDays	= cDate.getDate();

			if (cYear == toYear && cMonth == toMonth && cDays == i) {
				var cTotal	= cYear + '' + dateFormat(cMonth) + '' + dateFormat(cDays);
				var cWeek	= cDate.getDay();

				//土曜日と日曜日のスタイル
				if (cWeek == 0) {
					tmp += '<tr>';
					count++;
					
					
					//稼働日と非稼働日分岐
					if(arrdiv[i-1]==0){
						classAry.push('ctodate');
					}else{
						classAry.push('csun');
					}
					
				}else if (cWeek == 6) {
					//稼働日と非稼働日分岐
					if(arrdiv[i-1]==0){
						classAry.push('ctodate');
					}else{
						classAry.push('csat');
					}
				}
				
				
				
				if (i == 1 && cWeek != 0) {
					count++;
					for (var j = 1;j <= cWeek;j++) {
						tmp += '<td> </td>';
					}
				}

				
				//if (totalDate == cTotal) {
				//	classAry.push('ctodate');
				//}
				
					//稼働日と非稼働日分岐
					if(arrdiv[i-1]==0){
						classAry.push('ctodate');
					}else{
						classAry.push('csun');
					}
				
				
				//※※※※後で消す用(レイアウト用に直接記入)※※※※
				//if("20121213" == cTotal ||"20121214" == cTotal ){
					//選択されている日のスタイル
				//	classAry.push('selectDay');
				//}
				if (classAry.length >= 1) {
					classStr = ' class="' + classAry.join(' ') + '"';
				}
				
				//マウスＯＶＥＲ
				var mouseOverStr = ' onMouseOver="mouse_cursor(this, '+ i +' ,'+ "'over'"+')" '
				//マウスＯＵＴ
				var mouseOutStr = ' onMouseOut="mouse_cursor(this, '+ i +' ,'+ "'out'"+')" '
				//onClick
				var onClickStr = ' onClick="check_checkbox(this, '+ i +')"'
				
				
				tmp += '<td id= "check_'+ i+'" '+ classStr + mouseOverStr + mouseOutStr + onClickStr + ' >' + i + '</td>';
				
				
				//
				//======================================================================================
				//土曜日と日曜日以外のvalue値を区分
				//--------------------------------------------------------------------------------------
				var hollyDay="";
				var checkDay="";
				
				if(arrdiv[i-1]!=0){
					hollyDay ="01";
					checkDay="1";
					
				}else{
					hollyDay ="00";
					checkDay="0";
				}
				
				tmp += '<input type="hidden" name="style_cd" value="'+hollyDay+'" id="hdId'+ i +'" >';
				tmp += '<input type="hidden" name="input_flg" value="'+checkDay+'" id="hdInput'+ i +'" >';
				//---------------------------------------------------------------------------------------
				
				
				if (cWeek == 6) {
					tmp += '</tr>';
				}
				
			}
		}
		if (cWeek != 6) {
			var last = 6 - (cWeek);
			for (var k = 1;k <= last;k++) {
				tmp += '<td> </td>';
			}
			tmp += '</tr>';
		}
		count = 6 - count;
		if (count != 0) {
			for (var l = 1;l <= count;l++) {
				tmp += '<tr>';
				for (var m = 0;m < 7;m++) {
					tmp += '<td> </td>';
				}
				tmp += '</tr>';
			}
		}
		tmp += '</table>';

		document.getElementById('calendar').innerHTML = tmp;
		
		return false;
	}

	function dateFormat(str) {
		if (str < 10) {
			return '0' + str;
		} else {
			
			return str;
		}
	}

	// 月の移動ボタンの有無[1 or 0]
	var changebtn = 0;
	
	
	
	//---------------------------
	// マウスカーソルの処理
	//---------------------------
	function mouse_cursor(changeTD ,checkId ,status){
		
		if(status == "out"){
			// 変更もとの色の設定を取得
			ColorFlag = document.getElementById("hdId"+checkId).value;
			if(ColorFlag == "01"){
			
				changeTD.style.backgroundColor = "#FFC0CB";
			}else{
				changeTD.style.backgroundColor = "#FFFFFF";
			}
		}else if(status == "over"){
			
			// 変更もとの色の設定を取得
			changeTD.style.backgroundColor = "#FFFF99";
		}
		
	}
	
	
	
	
	//---------------------------
	// カレンダーの選択処理
	//---------------------------
	function check_checkbox(obj,checkId){
		var ColorFlag;
		var	changeTD;
		
		changeTD  = document.getElementById("check_"+checkId);
		ColorFlag = document.getElementById("hdId"+checkId);
		
		if(ColorFlag.value == "00"){		
			changeTD.style.backgroundColor = "#FFC0CB";
			ColorFlag.value = "01";
		}else{
			changeTD.style.backgroundColor = "#FFFFFF";
			ColorFlag.value = "00";
		}
		
		change_input_flg(checkId);
		
	}
	
	//---------------------------
	// 変更フラグの変更処理
	//---------------------------
	function change_input_flg(checkId){
		input_flg_obj = document.getElementById("hdInput"+checkId)
		if(input_flg_obj.value=="0"){
			input_flg_obj.value = 1;
		}else{			
			input_flg_obj.value = 0;
		}
	}
	
	
	